// pages/order/list/index.js
import { getOrderList } from '../../../api/orderpay'
Page({
  // 页面的初始数据
  data: {
    orderList: [],
    page: 1,
    linit: 10,
    total: 0,
    isLoading: false
  },
  async getPageData(){
    const { page,linit } = this.data
    this.isLoading = true
    const { code, data } = await getOrderList(page,linit)
    this.data.isLoading = false
    if(code === 200){
      this.setData({
        orderList: [...this.data.orderList, ...data.records],
        total: data.total
      })
    }
  },
  onReachBottom(){
    const { orderList, page, total, isLoading } = this.data
    if(isLoading) return
    if(total === orderList.length){
      wx.toast({title: '数据加载完毕'})
      return
    }
    this.setData({page: page + 1 })
    this.getPageData()
  },
  onLoad(){
    this.getPageData()
  }
})
